﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.IO;
using MaterialEditor;

namespace LevelEditor
{
    public static class EffectManager
    {
        public static Effect BasicShader;

        public static Effect FlatShader;

        public static Effect TerrainShader;

        public static Effect DepthQueue;

        public static Effect heightMapShader;

        private static string Root
        {
            get { return Environment.CurrentDirectory + "\\Content\\"; }
        }

        private static Effect compileEffect(string filename)
        {
            ContentBuilder b = MainMenu.instance.contentBuilder;
            b.Clear();

            string name = Path.GetFileName(filename).Split(new char[] { '.' })[0];

            b.Add(filename, name, "EffectImporter", "EffectProcessor");
            string err_msg = b.Build();
            if (string.IsNullOrEmpty(err_msg))
            {
                Effect outval = MainMenu.instance.content.Load<Effect>(name);
                return outval;
            }
            else
                System.Windows.Forms.MessageBox.Show(err_msg);
            return null;
        }

        public static void Inilitize()
        {
            BasicShader = compileEffect(Root + "effects\\BasicShader.fx");
            FlatShader = compileEffect(Root + "effects\\FlatShader.fx");
            TerrainShader = compileEffect(Root + "effects\\renderTerrain.fx");
            DepthQueue = compileEffect(Root + "effects\\DepthQueue.fx");
            heightMapShader = compileEffect(Root + "effects\\HeightMap.fx");
        }
    }
}